package org.codeart.juc.thread;

public class YieldDemo {

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 100; i++) {
                if (i == 50) {
                    // 让步
                    Thread.yield();
                }
                System.out.printf("t1: %d\n", i);
            }
        }, "t1");
        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 100; i++) {
                System.out.printf("t2: %d\n", i);
            }
        }, "t2");
        t1.start();
        t2.start();
    }

}
